package com.easysoft.framework.enterprise.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.enterprise.mapper.SysEnterpriseMapperExtd;
import com.easysoft.framework.enterprise.model.SysEnterprise;
import com.easysoft.framework.enterprise.model.SysEnterpriseQuery;
import com.easysoft.framework.enterprise.model.SysEnterpriseView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by try on 2017/8/22.
 */
@Service("service.SysEnterpriseService")
public class SysEnterpriseService {

    @Autowired
    @Qualifier("mapper.SysEnterpriseMapperExtd")
    private SysEnterpriseMapperExtd sysEnterpriseMapperExtd;


    @DataSource(DataSource.SLAVE)
    public List<SysEnterpriseView> selectSysProductByPage(Page page, SysEnterpriseQuery query) {
        int maxRow = sysEnterpriseMapperExtd.selectCountAllSysEnterprise(query);
        if (maxRow == 0){
            return new ArrayList<SysEnterpriseView>();
        }
        page.setMaxRow(maxRow);
        return sysEnterpriseMapperExtd.selectSysEnterpriseByPage(page,query);
    }

    @DataSource(DataSource.MASTER)
    public int addSysEnterprise(SysEnterprise sysEnterprise) {
        sysEnterprise.setId(UUIDUtils.getUUID());
        sysEnterprise.setCreateTime(new Date());
        return sysEnterpriseMapperExtd.insertSelective(sysEnterprise);
    }

    @DataSource(DataSource.SLAVE)
    public SysEnterprise selectSysEnterpriseById(String id) {

        return sysEnterpriseMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysEnterprise(SysEnterprise sysEnterprise){
        return sysEnterpriseMapperExtd.updateByPrimaryKeySelective(sysEnterprise);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysEnterprise(String id) {

        return sysEnterpriseMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.SLAVE)
    public List<SysEnterpriseView> selectAllSysEnterprise() {
        return sysEnterpriseMapperExtd.selectAllSysEnterprise();
    }

    @DataSource(DataSource.SLAVE)
    public List<Map<String, String>> selectSysEnterprise(int status) {
        return sysEnterpriseMapperExtd.selectSysEnterprise(status);
    }
}
